using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace LMSData
{
	/// <summary>
	/// Strongly-typed collection for the UserAssessment class.
	/// </summary>
	[Serializable]
	public partial class UserAssessmentCollection : ActiveList<UserAssessment, UserAssessmentCollection> 
	{	   
		public UserAssessmentCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the UserAssessment table.
	/// </summary>
	[Serializable]
	public partial class UserAssessment : ActiveRecord<UserAssessment>
	{
		#region .ctors and Default Settings
		
		public UserAssessment()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public UserAssessment(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public UserAssessment(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public UserAssessment(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("UserAssessment", TableType.Table, DataService.GetInstance("LMS"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarUserAssessmentID = new TableSchema.TableColumn(schema);
				colvarUserAssessmentID.ColumnName = "UserAssessmentID";
				colvarUserAssessmentID.DataType = DbType.Int32;
				colvarUserAssessmentID.MaxLength = 0;
				colvarUserAssessmentID.AutoIncrement = true;
				colvarUserAssessmentID.IsNullable = false;
				colvarUserAssessmentID.IsPrimaryKey = true;
				colvarUserAssessmentID.IsForeignKey = false;
				colvarUserAssessmentID.IsReadOnly = false;
				colvarUserAssessmentID.DefaultSetting = @"";
				colvarUserAssessmentID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserAssessmentID);
				
				TableSchema.TableColumn colvarUserID = new TableSchema.TableColumn(schema);
				colvarUserID.ColumnName = "UserID";
				colvarUserID.DataType = DbType.Int32;
				colvarUserID.MaxLength = 0;
				colvarUserID.AutoIncrement = false;
				colvarUserID.IsNullable = false;
				colvarUserID.IsPrimaryKey = false;
				colvarUserID.IsForeignKey = true;
				colvarUserID.IsReadOnly = false;
				colvarUserID.DefaultSetting = @"";
				
					colvarUserID.ForeignKeyTableName = "User";
				schema.Columns.Add(colvarUserID);
				
				TableSchema.TableColumn colvarAssessmentID = new TableSchema.TableColumn(schema);
				colvarAssessmentID.ColumnName = "AssessmentID";
				colvarAssessmentID.DataType = DbType.Int32;
				colvarAssessmentID.MaxLength = 0;
				colvarAssessmentID.AutoIncrement = false;
				colvarAssessmentID.IsNullable = false;
				colvarAssessmentID.IsPrimaryKey = false;
				colvarAssessmentID.IsForeignKey = true;
				colvarAssessmentID.IsReadOnly = false;
				colvarAssessmentID.DefaultSetting = @"";
				
					colvarAssessmentID.ForeignKeyTableName = "Assessment";
				schema.Columns.Add(colvarAssessmentID);
				
				TableSchema.TableColumn colvarCourseID = new TableSchema.TableColumn(schema);
				colvarCourseID.ColumnName = "CourseID";
				colvarCourseID.DataType = DbType.Int32;
				colvarCourseID.MaxLength = 0;
				colvarCourseID.AutoIncrement = false;
				colvarCourseID.IsNullable = false;
				colvarCourseID.IsPrimaryKey = false;
				colvarCourseID.IsForeignKey = true;
				colvarCourseID.IsReadOnly = false;
				colvarCourseID.DefaultSetting = @"";
				
					colvarCourseID.ForeignKeyTableName = "Course";
				schema.Columns.Add(colvarCourseID);
				
				TableSchema.TableColumn colvarIsDeleted = new TableSchema.TableColumn(schema);
				colvarIsDeleted.ColumnName = "IsDeleted";
				colvarIsDeleted.DataType = DbType.Boolean;
				colvarIsDeleted.MaxLength = 0;
				colvarIsDeleted.AutoIncrement = false;
				colvarIsDeleted.IsNullable = false;
				colvarIsDeleted.IsPrimaryKey = false;
				colvarIsDeleted.IsForeignKey = false;
				colvarIsDeleted.IsReadOnly = false;
				
						colvarIsDeleted.DefaultSetting = @"((0))";
				colvarIsDeleted.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsDeleted);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["LMS"].AddSchema("UserAssessment",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("UserAssessmentID")]
		public int UserAssessmentID 
		{
			get { return GetColumnValue<int>("UserAssessmentID"); }

			set { SetColumnValue("UserAssessmentID", value); }

		}

		  
		[XmlAttribute("UserID")]
		public int UserID 
		{
			get { return GetColumnValue<int>("UserID"); }

			set { SetColumnValue("UserID", value); }

		}

		  
		[XmlAttribute("AssessmentID")]
		public int AssessmentID 
		{
			get { return GetColumnValue<int>("AssessmentID"); }

			set { SetColumnValue("AssessmentID", value); }

		}

		  
		[XmlAttribute("CourseID")]
		public int CourseID 
		{
			get { return GetColumnValue<int>("CourseID"); }

			set { SetColumnValue("CourseID", value); }

		}

		  
		[XmlAttribute("IsDeleted")]
		public bool IsDeleted 
		{
			get { return GetColumnValue<bool>("IsDeleted"); }

			set { SetColumnValue("IsDeleted", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public LMSData.AssessmentResponseCollection AssessmentResponseRecords()
		{
			return new LMSData.AssessmentResponseCollection().Where(AssessmentResponse.Columns.UserAssessmentID, UserAssessmentID).Load();
		}

		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Assessment ActiveRecord object related to this UserAssessment
		/// 
		/// </summary>
		public LMSData.Assessment Assessment
		{
			get { return LMSData.Assessment.FetchByID(this.AssessmentID); }

			set { SetColumnValue("AssessmentID", value.AssessmentID); }

		}

		
		
		/// <summary>
		/// Returns a Course ActiveRecord object related to this UserAssessment
		/// 
		/// </summary>
		public LMSData.Course Course
		{
			get { return LMSData.Course.FetchByID(this.CourseID); }

			set { SetColumnValue("CourseID", value.CourseID); }

		}

		
		
		/// <summary>
		/// Returns a User ActiveRecord object related to this UserAssessment
		/// 
		/// </summary>
		public LMSData.User User
		{
			get { return LMSData.User.FetchByID(this.UserID); }

			set { SetColumnValue("UserID", value.UserID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varUserID,int varAssessmentID,int varCourseID,bool varIsDeleted)
		{
			UserAssessment item = new UserAssessment();
			
			item.UserID = varUserID;
			
			item.AssessmentID = varAssessmentID;
			
			item.CourseID = varCourseID;
			
			item.IsDeleted = varIsDeleted;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varUserAssessmentID,int varUserID,int varAssessmentID,int varCourseID,bool varIsDeleted)
		{
			UserAssessment item = new UserAssessment();
			
				item.UserAssessmentID = varUserAssessmentID;
				
				item.UserID = varUserID;
				
				item.AssessmentID = varAssessmentID;
				
				item.CourseID = varCourseID;
				
				item.IsDeleted = varIsDeleted;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string UserAssessmentID = @"UserAssessmentID";
			 public static string UserID = @"UserID";
			 public static string AssessmentID = @"AssessmentID";
			 public static string CourseID = @"CourseID";
			 public static string IsDeleted = @"IsDeleted";
						
		}

		#endregion
	}

}

